﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using kxcxw.Data;
using kxcxw.Data.Entities;
using System.Security.Cryptography;
using System.Text;

namespace kxcxw.Data.Common
{
    public class AccountRepositories
    {
        private KXCXWDBContext db = new KXCXWDBContext();
        public bool ValidLoginNameIsAlreadyExists(string LoginName)
        {
            int count = (from q in db.SysUserInfoes
                         where q.UserName == LoginName
                         select q).ToList().Count;
            return count > 0;
        }
        public bool ValidEmailAddressIsAlreadyExists(string EmailAddress)
        {
            int count = (from q in db.SysUserInfoes
                         where q.Email == EmailAddress
                         select q).ToList().Count;
            return count > 0;
        }

        public string[] GetRoles(string userName)
        {
            SysUserInfo user = (from q in db.SysUserInfoes
                                where q.UserName == userName
                                select q).FirstOrDefault();

            SysItemDetial sid = (from q in db.SysItemDetials
                                 where q.ItemDeitalID == user.UserType
                                 select q).FirstOrDefault();
            return new string[] { sid.itemDetialName };

        }

        //16位加密 
        public static string GetMd5_16(string ConvertString)
        {
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string t2 = BitConverter.ToString(md5.ComputeHash(UTF8Encoding.Default.GetBytes(ConvertString)), 4, 8);
            t2 = t2.Replace("-", "");
            return t2;
        } 

        //public bool ValidEmailActivation(string uid, string activeId)
        //{
        //}
    }
}